package com.baizan.daka.ui.activity

import android.content.Context
import android.content.Intent
import android.text.Html
import android.view.View
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient
import com.baizan.base.BaseActivity
import com.baizan.daka.MyApp
import com.baizan.daka.base.BasePresenter
import com.baizan.daka.event.HomeEvent
import com.baizan.daka.event.PayEvent
import com.dianzan.daka.R
import kotlinx.android.synthetic.main.act_web.*
import org.greenrobot.eventbus.EventBus

class WebActivity : BaseActivity<BasePresenter>() {
    companion object{
        fun start(context: Context,url:String) {
            val intent = Intent(context, WebActivity::class.java)
            intent.putExtra("url",url)
            context.startActivity(intent)
        }
    }


    override fun initPresenter(): BasePresenter? = null

    override fun layoutId(): Int = R.layout.act_web

    override fun initData() {
       val content = intent.getStringExtra("url")
        webview.settings.javaScriptEnabled = true
        webview.webViewClient =object :WebViewClient(){
            override fun shouldOverrideUrlLoading(view: WebView?,request: WebResourceRequest?): Boolean {
//                view?.loadData(content, "text/html", "UTF-8")
                return super.shouldOverrideUrlLoading(view, request)
            }
        }
        webview.loadData(content, "text/html", "UTF-8")
        action_bar.setLeftOnClickListener(View.OnClickListener {
            EventBus.getDefault().post(PayEvent())
            EventBus.getDefault().post(HomeEvent(0))
            MyApp.finishAct(FlowPackageActivity::class.java)
            finish()
        })


    }

    override fun initView() {
    }

    override fun start() {
    }

}